<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Radiator Model Dictionary Import Management</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
		<style type="text/css">
.a-upload {
	padding: 4px 10px;
	height: 20px;
	line-height: 20px;
	position: relative;
	cursor: pointer;
	color: #888;
	background: #fafafa;
	border: 1px solid #ddd;
	border-radius: 4px;
	overflow: hidden;
	display: inline-block;
	*display: inline;
	*zoom: 1
}

.a-upload  input {
	position: absolute;
	font-size: 100px;
	right: 0;
	top: 0;
	opacity: 0;
	filter: alpha(opacity = 0);
	cursor: pointer
}

.a-upload:hover {
	color: #444;
	background: #eee;
	border-color: #ccc;
	text-decoration: none
}
</style>
  </head>
  <script type="text/javascript">
  	function formVerify() {
  		var verify = true;
  		var absPath = $("input[name='attachFile']").val();
  		if(absPath!=null && $.trim(absPath)!="") {
  			var fileIndex = absPath.lastIndexOf("\\")>0?absPath.lastIndexOf("\\"):absPath.lastIndexOf("/");
  			//读取上传的文件名
  			var fileName = "";
  			if(fileIndex<0) {
  				fileName = absPath;
  			} else {
  				fileName = absPath.substring(fileIndex+1, absPath.length);
  			}
  			//读取上传附件的文件类型
			var dotIndex = fileName.lastIndexOf(".");
			var fileType = fileName.substring(dotIndex+1, fileName.length);
			var verifyTagIndex = "xls,xlsx".indexOf(fileType.toLowerCase());
			if(verifyTagIndex < 0) {
				Dialog.alert("Please upload files in XLS or XLSX format！");
				verify = false;
			}
  		}
  		return verify;
  	}
  
  	function submitTips() {
  		Dialog.alert("Data importing，please waiting。。。");
  	}
  	
  	/**
  	 * 热量表信息提交回调
  	 * @param {Object} data
  	 */
  	function uploadCallBack(data) {
  		var resJson = $.parseJSON(data);
  		if(resJson.success) {
  			Dialog.alert("Successful Operation！", function() {
  				var index = parent.layer.getFrameIndex(window.name)
				parent.window.frames["c_content_content"].location = path + "beshs/sinkerStandardDictAction!queryStandardSinkerPage.do?date"+new Date();
  				parent.layer.close(index);
  			});
  		} else {
  			Dialog.alert(resJson.msg, function() {
  				var index = parent.layer.getFrameIndex(window.name)
				parent.window.frames["c_content_content"].location = path + "beshs/sinkerStandardDictAction!queryStandardSinkerPage.do?date"+new Date();
  				parent.layer.close(index);
  			});
  		}
  	}
  </script>
  <body>
    <div class="content_all">
  		<!--导航条-->
  		<div class="insertinfo_table">
      		<form action="<%=basePath%>beshs/sinkerStandardDictActionJson!uploadSinkerDictBatch.do"
      			enctype="multipart/form-data" method="post" target="async_frame_submit" onsubmit="submitTips()">
      		  <iframe name="async_frame_submit" id="async_frame_submit" style="display: none;"></iframe>
      		  <table width="100%" border="0" cellspacing="0" cellpadding="0">
        		<tr>
        			<th rowspan="2">Excel File：</th>
          			<td>
          				<script type="text/javascript">
	          				$(function(){
	          					addListenerToFileField();
	    					});
	          				
	          				/**
	            			 * 为文件域追加状态切换事件处理函数
	            			 * @return {TypeName} 
	            			 */
	            			function addListenerToFileField() {
	            				$("input[name='attachFile']").change(function(){
             						var absPath = $("input[name='attachFile']").val();
             						if(absPath!=null && $.trim(absPath)!="") {
             							var fileIndex = absPath.lastIndexOf("\\")>0?absPath.lastIndexOf("\\"):absPath.lastIndexOf("/");
             							//读取上传的文件名
             							var fileName = "";
             							if(fileIndex<0) {
             								fileName = absPath;
             							} else {
             								fileName = absPath.substring(fileIndex+1, absPath.length);
             							}
             							//读取上传附件的文件类型
             							var dotIndex = fileName.lastIndexOf(".");
             							var fileType = fileName.substring(dotIndex+1, fileName.length);
             							var verifyTagIndex = "xls,xlsx".indexOf(fileType.toLowerCase());
             							if(verifyTagIndex < 0) {
             								Dialog.alert("Please upload files in XLS or XLSX format！");
             								//清空文件域
                     						var attachFile = $("input[name='attachFile']");
                     						attachFile.after(attachFile.clone().val(""));
                     						attachFile.remove();
                     						//文件域事件监听
                     						addListenerToFileField();
             								return;
             							}
             							$("input[name='attachFile']").hide("fast");
             							//加载文件名
             							var fileNameLoad = "<p class='fileName_load_txt'>" + 
             													fileName + "&nbsp;&nbsp;" +
             													"<a class='fileName_load_txt' style='text-decoration: underline' target='_self' href='javascript:void(0)'>Delete</a>" +
             												"</p>";
             							$("input[name='attachFile']").parent("td").append(fileNameLoad);
             							//文件名删除处理
             							$("a.fileName_load_txt").click(function(){
             								removeFileNameTxt();
             							});
             							//根据文件类型提交不同的请求服务
//              							if("txt" == fileType.toLowerCase()) { //分配表数据TXT上传
//              								$("form:eq(0)").attr("action", path+"beshs/assignMeterDataFileActionJson!uploadMeterDataFile.do");
//              							}
//              							if("xml" == fileType.toLowerCase()) { //掌机数据上传
//              								$("form:eq(0)").attr("action", path+"interfaces/pdaUploadActionJson!uploadPdaData.do");
//              							}
             						}
             					});
	            			 }
	            			 
	            			 /**
         					 * 删除上传文件加载名称
         					 */
         					function removeFileNameTxt() {
         						$("p.fileName_load_txt").remove();
         						//清空文件域
         						var attachFile = $("input[name='attachFile']");
         						attachFile.after(attachFile.clone().val(""));
         						attachFile.remove();
         						$("input[name='attachFile']").show("fast");
         						//文件域事件监听
         						addListenerToFileField();
         					}
          				</script>
          				  				 <a href="javascript:;" class="a-upload"> <input type="file" name="attachFile" id="">Upload File</a> 
          			</td>
        		</tr>
        		<tr>
        			<td><span style="color:red">Prompt: only support *.xls | *.xlsx  format file!</span></td>
        		</tr>
        		<tr>
          			<td style="border:none;" colspan="4" align="center">
          				<input name="submit" type="submit" value="Submit" class="s_btn" onclick="return formVerify();" />
            			<input name="winClose" type="button" value="Close" class="s_btn" onclick="javascript:window.close();" /></td>
        		</tr>
      		</table></form>
  		</div>
	</div>
	<div class="clear"></div>
  </body>
</html>
